package com.itheima.reggie.common;

/**
 * @author Mylinja 2021-12-16 星期四 19:43
 * 基于ThreadLocal封装工具类，用来获取并传递session域对象中的id
 */
public class BaseContext {
    private static final ThreadLocal<Long> THREAD_LOCAL = new ThreadLocal<>();
    /**
     * 设置值
     * @param id 域对象的id
     */
    public static void setCurrentId(Long id){
        THREAD_LOCAL.set(id);
    }
    /**
     * 获取值
     * @return 返回线程中的id
     */
    public static Long getCurrentId(){
        return THREAD_LOCAL.get();
    }

    /**
     * 移除值
     */
    @SuppressWarnings("unused")
    public static void removeCurrentId(){
        THREAD_LOCAL.remove();
    }
}
